package cn.tedu.sp04.controller;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.sp01.pojo.Order;
import cn.tedu.sp01.pojo.User;
import cn.tedu.sp01.service.OrderService;
import cn.tedu.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId){
        Order order = orderService.getOrder(orderId);
        return JsonResult.build().code(200).data(order);
    }
    @GetMapping("/add")
    public JsonResult<?> addOrder(){
        Order order = new Order("kljashdlkhasdklsajdkla",
                Arrays.asList(new Item[]{
                        new Item(1,"商品1",4898),
                        new Item(2,"商品2",466),
                        new Item(3,"商品3",123),
                        new Item(4,"商品4",321),
                        new Item(5,"商品5",4456),
                }),
                new User(8,null,null)
        );
        return JsonResult.build().code(200).msg("创建订单成功");
    }
    //处理浏览器自动请求的图标文件
    @GetMapping("/favicon.ico")
    public void ico(){}
}
